// https://www.nowcoder.com/practice/fd55637d3f24484e96dad9e992d3f62e?tpId=389&tqId=2032484&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int weights[3600];
int values[3600];
int dp[13000];
int dpMax[13000];

int knapsack(const int w, const int n) {
    dp[0] = 0;
    memset(dpMax, -1, sizeof(dpMax));
    dpMax[0] = 0;

    for (int i=1; i<=n; i++) {
        for (int j=w; j >= weights[i]; j--) {
            dp[j] = max(dp[j], dp[j-weights[i]]+values[i]);
            // 刚好装满
            if (dpMax[j-weights[i]] != -1) {
                dpMax[j] = max(dpMax[j], dpMax[j-weights[i]]+values[i]);
            }
        }
    }

    if (dpMax[w] == -1) {
        dpMax[w] = 0;
    }
    return dp[w];
}

int main() {
    int n, w;
    scanf("%d%d", &n, &w);
    for (int i=1; i<=n; i++) {
        scanf("%d%d", &weights[i], &values[i]);
    }
    printf("%d\n", knapsack(w, n));
    printf("%d\n", dpMax[w]);

    return 0;
}
